package top.jfunc.common.db.data;

import java.util.function.Consumer;
import java.util.function.IntConsumer;

import javax.sql.DataSource;

/**
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
 * @since 1.0 2022/11/25 11:45
 */
public abstract class DataExtractorBuilderSupport<Sub extends DataExtractorBuilderSupport<Sub>> {

  protected DataSource dataSource;
  protected IntConsumer successCallback;
  protected PreparedStatementSetter statementPostProcessor;
  protected Consumer<Throwable> exceptionConsumer = ExceptionUtils::sneakyThrow;

  public Sub dataSource(DataSource dataSource) {
    this.dataSource = dataSource;
    return self();
  }

  protected abstract Sub self();

  public Sub errorHandling(Consumer<Throwable> consumer) {
    this.exceptionConsumer = consumer;
    return self();
  }

  public Sub onSuccess(IntConsumer successCallback) {
    this.successCallback = successCallback;
    return self();
  }

  public Sub config(PreparedStatementSetter statementPostProcessor) {
    this.statementPostProcessor = statementPostProcessor;
    return self();
  }

}
